package com.outsourcing.bottle.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.outsourcing.bottle.R;
import com.outsourcing.bottle.domain.BottleLikeEntry;
import com.outsourcing.bottle.util.AppContext;
import com.outsourcing.bottle.util.ImageLoader;

public class GridLikeAdapter extends BaseAdapter{
	private Context context;
	private List<BottleLikeEntry> arrayList;
	private ImageLoader imageLoader;

	public GridLikeAdapter(Context context, List<BottleLikeEntry> arrayList, AbsListView like_grid) {
		this.context = context;
		this.arrayList = arrayList;
		imageLoader = new ImageLoader(context,
		AppContext.BottleTimelineIcon);
	}

	@Override
	public int getCount() {
		return (null != arrayList && arrayList.size() > 0) ? arrayList
				.size() : 0;
	}

	@Override
	public Object getItem(int position) {
		return (null != arrayList && arrayList.size() > 0) ? arrayList
				.get(position) : null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View convertView,
			ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.bottle_like_avatar_listitem, null);
			holder.mheadView = (ImageView) convertView
					.findViewById(R.id.head_photo);
			holder.mLikeView = (ImageView) convertView
					.findViewById(R.id.like_photo);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		BottleLikeEntry item = (BottleLikeEntry) getItem(position);
//		holder.mheadView.setDefaultImage(R.drawable.avatar_default_small);
//		holder.mheadView.setImageUrl(item.getLike_avatar(),
//				AppContext.BottleTimelineIcon, position, like_grid);
		 imageLoader.DisplayImage(item.getLike_avatar(), holder.mheadView,
		 R.drawable.avatar_default_small);

		switch (item.getLike_type()) {
		case 1:// 喜欢
			holder.mLikeView.setImageResource(R.drawable.like_red2);
			break;
		case 2:// 不喜欢
			holder.mLikeView.setImageResource(R.drawable.like_black2);
			break;
		default:
			holder.mLikeView.setVisibility(View.GONE);
			break;
		}
		return convertView;
	}

	class ViewHolder {
		ImageView mheadView;
		ImageView mLikeView;
	}
}
